package com.jgsu.farm.mapper.sql;

import com.jgsu.farm.entity.User;
import com.jgsu.farm.mapper.provider.ExpertProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 *专家用户信息管理模块
 * */
@Repository
public interface UserMapperSql {
    @Delete("delete from user where userID = #{userid}")
    int deleteUserByID(Integer userid);

    /**
     * 修改专家用户信息
     * */
    @Update("update user set phone = #{phone},password = #{password},role = #{role},name = #{name},nickname = #{nickname},email = #{email},address = #{address},postcode = #{postcode},photo = #{photo},introduction = #{introduction},state = #{state} where userID = #{userid}")
    Integer modifyExpertMsg(@Param("userid") Integer userid,@Param("password") String password,@Param("role") Integer role,
                            @Param("name") String name,@Param("nickname") String nickname,
                            @Param("phone")  String phone,@Param("email") String email,@Param("address") Integer address,
                            @Param("postcode") String postcode,@Param("photo") String photo,
                            @Param("introduction")  String introduction,@Param("state") Integer state);

    /*---------------------------普通用户信息管理————————————————*/
    @Select("select * from user where phone = #{phone} and role = 3")
    User selectGeneralByPhone(String phone);

    @Delete("delete from user where phone = #{phone} and role = 3")
    int deleteGeneralByPhone(String phone);


    @Select("select userID from user where userID = #{userid}")
    Integer selectId(Integer userid);

    @SelectProvider(type = ExpertProvider.class,method = "findExpertListByState")
    List<User> selectUserByState(@Param(value = "role") Integer role,@Param(value = "state") Integer  state);

    /**
     * 根据id查询用户
     */
    @Select("select * from user where userid = #{userid} and role = #{role} and state = #{state}")
    User selectUserById(Integer userid,Integer role,Integer state);
}

